<template>
  <div class="list">
    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
        <a-input placeholder="用户名/手机号" style="width: 180px;margin-right:10px;" v-model="key" allowClear :size="size"
          @input="onSearch" />
         <a-input placeholder="用户ID" style="width: 180px;margin-right:10px;" v-model="find_user_id" allowClear :size="size"
          @input="onSearch" />
        <a-button :size="size" type="primary" @click="refreshData" style="margin-right:10px;">刷新</a-button>

      </div>

      <div style="margin-top: 4px;">
          <a-button type="primary" style="margin-right:10px;"  @click="isExport = !isExport">导出Excel</a-button>
      </div>

      <!-- <a-button type="primary" icon="plus" @click="handleCreate" v-if="!selectMode">创建{{resourceTypeText}}</a-button> -->
    </div>
    <a-table class="table" :rowKey="row => row.uuid" :dataSource="list" :pagination="pagination" :size="size">
      <a-table-column title="用户" width="100px">
        <template slot-scope="row">
          <div class="user">
            <img :src="row.user.headimg" alt="用户头像">
            <div>
              <div>{{ row.user.name }}</div>
              <div>{{row.user.phone}}</div>
              <div>ID:{{row.user.id}}</div>
            </div>
          </div>
        </template>
      </a-table-column>
      <a-table-column title="旧手机号" width="100px">
        <template slot-scope="row">
          <div>
            {{row.old_phone}}
          </div>
        </template>
      </a-table-column>
      <a-table-column title="新手机号" width="100px">
        <template slot-scope="row">
          <div>
            {{row.phone}}
          </div>
        </template>
      </a-table-column>
      <a-table-column title="变动类型" width="80px">
        <template slot-scope="row">
          <span v-if="row.sub_type === 1">用户修改</span>
          <span v-else-if="row.sub_type === 2">后台管理修改</span>
          <span v-else-if="row.sub_type === 3">批量导入修改</span>
        </template>
      </a-table-column>
      <a-table-column title="操作人" width="100px">
        <template slot-scope="row">
          <div>
            {{row.admin && row.admin.name || '-'}}
          </div>
        </template>
      </a-table-column>
      <a-table-column title="变动日期" dataIndex="created_at" width="80px">
        <template slot-scope="created_at">
          <span>{{ created_at | onlyDay }}</span>
        </template>
      </a-table-column>
    </a-table>

  </div>
</template>
<script>
  import moment from 'moment'
  import IDatePicker from "@/components/IDatePicker/IDatePicker.vue"

  const resourceType = 'users-phone-log'
  const resourceTypeText = '手机号修改记录'

  export default {
    components: {
      IDatePicker
    },
    props: {
      selectMode: {
        type: Boolean
      },
      params: {
        type: Object
      },
      size: {
        type: String,
        default: 'default'
      }
    },
    data() {
      return {
        isEdit: false,
        editUuid: '',
        resourceTypeText,
        exportOptions: {
          status: 'all',
          startTime: '',
          endTime: '',
          type: 'normal'
        },
        list: [],
        page: 1,
        per_page: 10,
        total: 0,
        key: '',
        find_user_id: '',
        category_id: undefined,
        assetInfo: {

        },
        isExport: false,
        filter: {
          min_day: '',
          max_day: ''
        }
      }
    },
    watch: {
      params() {
        this.refreshData()
      },
    },
    computed: {
      pagination() {
        return {
          defaultPageSize: this.per_page,
          defaultCurrent: this.page,
          total: this.total,
          onChange: (e) => {
            this.page = e
            this.fetchData()
          }
        }
      }
    },
    filters: {},
    created() {
      this.fetchData()
    },
    methods: {
      
      refreshData() {
        this.page = 1
        this.fetchData()
      },
      onSearch(e) {
		  this.page = 1
        this.fetchData()
      },
      fetchData() {
        this.isEdit = false
        this.$http.get(`/${resourceType}`, {
          params: {
            ...this.params,
            page: this.page,
            per_page: this.per_page,
            key: this.key,
            find_user_id: this.find_user_id,
          }
        }).then(res => {
          this.list = res.data.list
          this.total = res.data.item_total
        }).finally(() => {
          this.loading = false
        })


      },
     
    }
  }
</script>
<style lang="scss" scoped>
  .value-font {
    font-weight: 500;
    font-size: 110%;
  }
  .content-head {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .table {
    .thumb {
      height: 60px;
      border-radius: 6px;
    }

    .content-image {
      height: 60px;
      width: 60px;
      margin-right: 10px;
      margin-bottom: 10px;
      object-fit: cover;
      border-radius: 10px;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .user {
      display: flex;
      // flex-wrap: wrap;
      align-items: center;

      img {
        width: 26px;
        height: 26px;
        margin-right: 6px;
        border-radius: 50%;
        overflow: hidden;
      }

      .gender-man,
      .gender-woman {
        margin-left: 5px;
        font-size: 12px;
      }

      .gender-man {
        color: #409EFF;
      }

      .gender-woman {
        color: #F56C6C;
      }
    }
  }
</style>
